package tv.acgn.advertisement.publish.po;

import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import tv.acgn.advertisement.servicebase.enumconst.CommonStatus;

/**
 * @program: advertisement-ad-publish-po
 * @description: 广告推广计划 持久化类
 * @author: junG
 * @create: 2019-04-29 22:50
 **/

@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "ad_plan")
@Entity
@DynamicInsert
@DynamicUpdate
@Builder
public class AdPlanPO {

    @Id
    @Column(name = "plan_id", nullable = true, unique = true, length = 64)
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    private String planId;


    /**
     * 推广计划的用户 关联用户表的 {@link AdUserPO} userId
     *
     * @see AdUserPO - userId
     */
    @Id
    @Column(name = "user_id", nullable = false, unique = true, length = 64)
    private String userId;

    @Column(name = "plan_name", nullable = false)
    private String planName;

    /**
     * 推广计划状态 值只允许 {@link CommonStatus} 中包含的值
     *
     * @see CommonStatus
     */
    @Column(name = "plan_status", nullable = false)
    private Integer planStatus;

    /**
     * 推广计划 生效开始时间
     */
    @Column(name = "start_date", nullable = false)
    private LocalDateTime startDate;

    /**
     * 推广计划 生效结束时间
     */
    @Column(name = "end_date", nullable = false)
    private LocalDateTime endDate;

    @Column(name = "create_time", nullable = false)
    private LocalDateTime createTime;

    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    public AdPlanPO(String userId, String planName, LocalDateTime startDate, LocalDateTime endDate) {
        this.userId = userId;
        this.planName = planName;
        this.startDate = startDate;
        this.endDate = endDate;
        this.planStatus = CommonStatus.INVALID.getStatus();
        this.createTime = LocalDateTime.now();
        this.updateTime = LocalDateTime.now();
    }
}
